package com.yjd.bi.canal.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.stereotype.Component;

import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.yjd.bi.canal.dao.ICanalMessageDao;
import com.yjd.bi.canal.model.CanalMessageModel;
import com.yjd.comm.base.dao.impl.BaseDaoImpl;
import com.yjd.comm.util.FrameUtil;

/**
 * <b>description</b>：客户消息订单数据访问层 <br>
 * <b>time</b>：2016-07-13 15:14:27 <br>
 * <b>author</b>： ready percy-chen@hotmail.com
 */
@Component("canalMessageDao")
public class CanalMessageDaoImpl extends BaseDaoImpl implements ICanalMessageDao {

	private static final String SQLMAPNAMESPACE = CanalMessageModel.class.getName();
	private static final String PKNAME = "id";

	@Override
	public String getPrimaryKeyName() {
		return PKNAME;
	}

	@Override
	public String getSqlmapNamespace() {
		return SQLMAPNAMESPACE;
	}
	
	/**
	 * 获取监听的table列表
	 * 
	 * @param <T>
	 * @param paramMap
	 *            查询参数列表
	 * @return 返回结果列表
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	public List getTableList(boolean write)
			throws Exception {
		List list = this.getSqlMap(write).queryForList(
				this.getStatement("getTableList"), null);
		return list;
	}
	
	/**
	 * 新增model
	 * 
	 * @param <T>
	 * @param model
	 *            需要添加的model,需集成Model类
	 * @return 新增以后的model
	 * @throws Exception
	 */
	public Map insertByMessage(Map map, boolean write)
			throws Exception {
		 return (Map) this.getSqlMap(write).insert(this.getStatement("insertNew"),
				map);
	}
	

	/**
	 * 新增model
	 * 
	 * @param <T>
	 * @param model
	 *            需要添加的model,需集成Model类
	 * @return 新增以后的model
	 * @throws Exception
	 */
	public CanalMessageModel insertLog(CanalMessageModel model, boolean write)
			throws Exception {
		 return (CanalMessageModel) this.getSqlMap(write).insert(this.getStatement("insertLog"),
				 model);
	}
	
	/**
	 * 根据map更新数据
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public int updateByMessage(Map<Object, Object> paramMap, boolean write)
			throws Exception {
		return this.getSqlMap(write)
				.update(this.getStatement("updateNew"), paramMap);
	}
	
	
	/**
	 * 根据id删除数据
	 * 
	 * @param id
	 * @param write
	 * @return
	 * @throws Exception
	 */
	public int deleteByMessage(Map<Object, Object> paramMap, boolean write) throws Exception {
		return this.getSqlMap(write).delete(
				this.getStatement("deleteNew"),
				paramMap);
	}
	/**
	 * 执行ddl语句
	 * @param sql
	 * @param write
	 */
	public void excuteSql(String sql,boolean write){
			 this.getSqlMap(write).update(this.getStatement("excuteSql"), FrameUtil.newHashMap("sql",sql));
	}
}
